<template>
  <div>
    <van-image width="100vw" height="30vh" lazy-load :src="img" />
    <div class="user">
      <div class="tou">
        <img src="http://liufusong.top:8080/img/profile/avatar.png" alt="" />
        <div class="title">{{ nickname }}</div>
        <div class="dl" @click="fn" v-show="flag">
          <span>去登录</span>
        </div>
        <div class="dl" @click="fn1" v-show="!flag">
          <span>退出</span>
        </div>
        <div class="grzl" v-show="!flag">编辑个人资料</div>
      </div>
    </div>
    <div class="gr">
      <van-grid :column-num="3" :border="false">
        <!-- 功能没选 页面暂时跳不了 -->
        <van-grid-item icon="star-o" text="我的收藏" to="/" />
        <van-grid-item icon="wap-home-o" text="我的出租" to="/" />
        <van-grid-item icon="clock-o" text="看房记录" to="/" />
        <van-grid-item icon="debit-pay" text="成为房主" to="/" />
        <van-grid-item icon="manager-o" text="个人资料" to="/" />
        <van-grid-item icon="service-o" text="联系我们" to="/" />
      </van-grid>
    </div>
    <div class="bottompic">
      <img src="http://liufusong.top:8080/img/profile/join.png" alt="" />
    </div>
  </div>
</template>

<script>
import { getUserInfo } from '@/api/user'
import { delToken } from '@/utils/storage'
export default {
  name: 'profile-page',
  data() {
    return {
      nickname: '游客',
      img: 'http://liufusong.top:8080/img/profile/bg.png',
      flag: true
    }
  },
  methods: {
    fn() {
      this.$router.push('/login')
    },
    fn1() {
      delToken()
      this.$router.push('/login')
    }
  },
  async created() {
    try {
      this.flag = false
      const res = await getUserInfo()
      console.log(res.body)
      this.nickname = res.body.nickname
      this.img = 'http://liufusong.top:8080' + res.body.avatar
    } catch (error) {
      this.flag = true
      console.log(error)
    }
  }
}
</script>

<style scoped lang="less">
.van-image {
  position: relative;
}
.user {
  width: 319px;
  height: 165px;
  background-color: #fff;
  box-shadow: 0 0 10px 3px #ddd;
  position: absolute;
  top: 23vh;
  left: 28px;
  .tou {
    position: absolute;
    top: -35px;
    left: 124.5px;
    border: 5px solid #f5f5f5;
    box-shadow: 0 2px 2px #bdbdbd;
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background-color: #f5f5f5;
    img {
      width: 60px;
      height: 60px;
    }
  }
  .title {
    position: relative;
    left: -10px;
    width: 80px;
    color: #333;
    font-size: 13px;
    padding-top: 20px;
    padding-bottom: 13px;
    text-align: center;
  }
  .dl {
    position: absolute;
    left: -3px;
    width: 69px;
    height: 30px;
    background-color: #21b97a;
    border-radius: 15%;
    line-height: 30px;
    text-align: center;
    span {
      font-size: 13px;
      color: #fff;
    }
  }
  .grzl {
    position: relative;
    width: 200px;
    top: 40px;
    left: -5px;
    font-size: 12px;
    color: #999;
  }
}

.gr {
  margin-top: 135px;
}

.bottompic {
  width: 345px;
  height: 85px;
  img {
    width: 100%;
    margin-left: 15px;
  }
}
</style>
